/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.session;

import com.google.common.collect.Lists;
import com.thienloc.omap.entity.TblAlarm;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
@Stateless
public class TblAlarmFacade extends AbstractFacade<TblAlarm> {

    @PersistenceContext(unitName = "omapPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TblAlarmFacade() {
        super(TblAlarm.class);
    }

    public List<TblAlarm> findByAlarmTimeRange(Date startDate, Date endDate) throws Exception {
        try {
            TypedQuery<TblAlarm> q = em.createNamedQuery("TblAlarm.findByAlarmTimeRange", TblAlarm.class);
            q.setParameter("startDate", startDate);
            q.setParameter("endDate", endDate);
            return q.getResultList();
        } catch (NoResultException ex) {
            return Lists.newArrayListWithCapacity(0);
        } catch (Exception ex) {
            LoggerFactory.getLogger(TblAlarmFacade.class.getName()).error("", ex);
            return Lists.newArrayListWithCapacity(0);
        }
    }
}
